package cn.kgc.controller;

import cn.kgc.annotation.LoginType;
import cn.kgc.annotation.RequireLogin;
import cn.kgc.grace.result.GraceJSONResult;
import cn.kgc.interceptor.JwtInterceptor;
import cn.kgc.service.SysParamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wangyue
 * @version 1.0
 */
@RestController
@RequestMapping("/sys")
@Api(tags = "系统参数相关接口")
public class SysParamsController {

    @Resource
    private SysParamsService sysParamsService;


    @GetMapping("/modifyRefreshMaxCount")
    @ApiOperation(value = "修改简历最大刷新次数")
    @RequireLogin(
            value = LoginType.USER_ADMIN_LOGIN
    )
    public GraceJSONResult  modifyRefreshMaxCount(int maxCount){
        sysParamsService.modifySysParams(maxCount);
        return GraceJSONResult.ok();
    }

    @GetMapping("/getRefreshMaxCount")
    @ApiOperation(value="获取简历最大刷新次数")
    @RequireLogin(
            value = LoginType.USER_ADMIN_LOGIN
    )
    public GraceJSONResult getRefreshMaxCount(){
        return GraceJSONResult.ok(sysParamsService.getRefreshMaxCount());
    }

    @GetMapping("/refreshResume")
    @ApiOperation(value="刷新简历信息")
    @RequireLogin({
            LoginType.USER_APP_LOGIN
    })
    public GraceJSONResult refreshResume(String resumeId) {
        //获得登录的用户ID
        String loginUserId = JwtInterceptor.userIds.get();
        //刷新简历
        return GraceJSONResult.ok(sysParamsService.refreshResume(resumeId,loginUserId));
    }

}